package com.szy.news.activity;

/**
 * @author 朱培文
 * 反馈
 * */
//import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class SendActivity extends BaseActivity implements OnClickListener{
	private EditText meditText;
	private Button submitbtn;
	private ImageView btn_back;
	private Feedback feedback;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_send);

		meditText = (EditText) findViewById(R.id.help_feedback);
		meditText.requestFocus();
		btn_back = (ImageView) findViewById(R.id.help_imageback);
		btn_back.setOnClickListener(this);
		submitbtn = (Button) findViewById(R.id.help_submit);
		submitbtn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		int  id = v.getId();
		final Intent intent;
		if (id == R.id.help_imageback) {
			intent = new Intent();
			intent.setClass(SendActivity.this, SetActivity.class);
			startActivity(intent);
			finish();
		} else if (id == R.id.help_submit) {
			/**1-8
			 * 网络状态判断
			 * 
			 * */
			ConnectivityManager manger = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo info = manger.getActiveNetworkInfo();
			if (info != null && info.isConnected()) {
//				Toast.makeText(SendActivity.this, "联网", Toast.LENGTH_SHORT).show();
				String et = meditText.getText().toString().trim();
				if (et.equals("")) {
					Toast.makeText(SendActivity.this, "请输入你的建议，谢谢！", Toast.LENGTH_SHORT).show();
					return;
				} else {
					feedback = new Feedback();
					feedback.setDes(et);
					feedback.save(this);
					intent = new Intent();
					intent.setClass(SendActivity.this, SetActivity.class);
					Toast.makeText(SendActivity.this, "谢谢您的建议！", Toast.LENGTH_SHORT).show();
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(intent);
//					finish();
				}
			} else {
				Toast.makeText(SendActivity.this, "当前无网络访问，无法提交您的宝贵意见", Toast.LENGTH_SHORT)
						.show();
				
//			String et = meditText.getText().toString().trim();
//			if (et.equals("")) {
//				Toast.makeText(SendActivity.this, "请输入你的建议，谢谢！", Toast.LENGTH_SHORT).show();
//				return;
//			} else {
//				feedback = new Feedback();
//				feedback.setDes(et);
//				feedback.save(this);
//				intent = new Intent();
//				intent.setClass(SendActivity.this, SetActivity.class);
//				Toast.makeText(SendActivity.this, "谢谢您的建议！", Toast.LENGTH_SHORT).show();
//				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//				startActivity(intent);
////				finish();
//			}
		}
	}
	}
}
